package lab03.test13;

import java.sql.*;

public class Test13 {
    public static void main(String[] args) {
//       	向数据库中插入十条示例数据；
//       	打印学生表的所有学生信息。
//       	删除 id 为5的学生信息；
//        查找 id 为3的学生并将其院系更改为“信息与工程学院”。

        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;

       // 向数据库中插入十条示例数据
        String sql="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql1="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql2="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql3="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql4="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql5="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql6="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql7="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql8="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";
        String sql9="insert into"
                +"t_student('stu_no','real_name','age','gender','department')"
                +"values('1002','张三',20，'男','信息与工程学院')";


        // 删除 id 为5的学生信息
        String sql10="delete from t_students where id=5";

        //查找 id 为3的学生并将其院系更改为“信息与工程学院”
        String sql11="select * from t_students where id=3";
        String sql12="update set department='信息与工程学院' where id=3";

        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection= DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "444455"
                    );

            statement=connection.createStatement();
            statement.execute(sql);
            statement.execute(sql1);
            statement.execute(sql2);
            statement.execute(sql3);
            statement.execute(sql4);
            statement.execute(sql5);
            statement.execute(sql6);
            statement.execute(sql7);
            statement.execute(sql8);
            statement.execute(sql9);
            statement.execute(sql10);
            statement.execute(sql11);
            statement.execute(sql12);


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }
}
